<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<!DOCTYPE html>
<html>
<head>
<title>根据文件类型下载文件</title>
</head>
<body>
  <%
      response.setContentType("text/html;charset=UTF-8");
      String mime = request.getParameter("mime");
      if (mime != null) {
          switch (mime) {
          case "word":
              // 转发请求
              pageContext.forward("mime-word.docx");
              break;
          case "pdf":
              out.print("pdf文件不存在<br>3秒后将返回至上一页");
              // 设置请求头
              response.setHeader("refresh", "3;URL=mime.jsp");
              break;
          case "excel":
              // 重定向请求
              response.sendRedirect("mime-excel.xlsx");
              break;
          }
      }
  %>
</body>
</html>
